package explorer;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.swing.JPanel;

import explorer.abstractFactory.IAbstractFactory;
import explorer.abstractFactory.ProxyFactoryLoader;
import explorer.abstractFactory.interfaces.IFolderIcon;
import explorer.abstractFactory.interfaces.IImageIcon;
import explorer.abstractFactory.interfaces.IMusicIcon;
import explorer.abstractFactory.interfaces.INullIcon;
import explorer.abstractFactory.interfaces.ITextIcon;
import explorer.abstractFactory.interfaces.IVideoIcon;

public class ImageLoader extends JPanel {

	
	private BufferedImage image;
	private String elementType= new String();
	
	public ImageLoader(File content, ProxyFactoryLoader factory){
		
		if (content.isDirectory()==true) {
			
			IFolderIcon folderImage=factory.createFolderIcon();
			image=folderImage.loadFolderImage();
			
		}else{
			
			elementType=content.getName();
			elementType=elementType.substring(elementType.indexOf(".")+1);
			
			if (elementType.equals("txt")) {

				ITextIcon  textIcon=factory.createTextIcon();
				image=textIcon.loadTextImage();
				
			}else if(elementType.equals("docx")){
				ITextIcon  textIcon=factory.createTextIcon();
				image=textIcon.loadTextImage();
			}else if(elementType.equals("pdf")){
				ITextIcon  textIcon=factory.createTextIcon();
				image=textIcon.loadTextImage();
			}else if(elementType.equals("PNG")){
				IImageIcon  imageIcon=factory.createImageIcon();
				image=imageIcon.loadImageImage();
			}else if(elementType.equals("jpg")){
				IImageIcon  imageIcon=factory.createImageIcon();
				image=imageIcon.loadImageImage();
			}else if (elementType.equals("mp3")) {
				IMusicIcon musicIcon=factory.createMusicIcon();
				image=musicIcon.loadMusicImage();				
			}else if (elementType.equals("mpg")) {
				IVideoIcon videoIcon=factory.createVideoIcon();
				image=videoIcon.loadVideoImage();
			}else if (elementType.equals("flv")) {
				IVideoIcon videoIcon=factory.createVideoIcon();
				image=videoIcon.loadVideoImage();
			}else{
				INullIcon nullIcon=factory.createNullIcon();
				image=nullIcon.loadNullImage();
				
			}
			
			
			
		}
		
		
		
		
	}
	
	@Override
	protected void paintComponent(Graphics graphics) {
		super.paintComponent(graphics);
	
		Graphics2D graphics2=(Graphics2D)graphics;
		graphics2.setBackground(Color.WHITE);

		graphics2.drawImage(image,10,2, null);
	}
}
